package com.stud.business.qb.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springdoc.core.annotations.ParameterObject;
import lombok.RequiredArgsConstructor;
import java.util.List;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.stud.common.annotation.Log;
import com.stud.common.core.controller.BaseController;
import com.stud.common.core.domain.Result;
import com.stud.common.enums.BusinessType;
import com.stud.business.qb.domain.QIntervalConfig;
import com.stud.business.qb.service.QIntervalConfigService;
import com.stud.common.utils.poi.ExcelUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.stud.common.core.page.TableDataInfo;

/**
 * 间隔配置Controller
 *
 * @author Stud
 * @date 2024-03-08
 */
@Tag(name = "间隔配置")
@RestController
@RequestMapping("/qb/qIntervalConfig")
@RequiredArgsConstructor
public class QIntervalConfigController extends BaseController {
    private final QIntervalConfigService qIntervalConfigService;

    @Operation(summary = "查询间隔配置列表")
    @PreAuthorize("@ss.hasPermi('qb:qIntervalConfig:list')")
    @GetMapping("/list")
    public TableDataInfo<QIntervalConfig> list(@ParameterObject QIntervalConfig qIntervalConfig) {
        startPage();
        Wrapper<QIntervalConfig> wrapper = new QueryWrapper<>(qIntervalConfig);
        List<QIntervalConfig> list = qIntervalConfigService.list(wrapper);
        return getDataTable(list);
    }

    @Operation(summary = "新增间隔配置")
    @PreAuthorize("@ss.hasPermi('qb:qIntervalConfig:add')")
    @Log(title = "间隔配置", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Boolean> add(@Validated @RequestBody QIntervalConfig qIntervalConfig) {
        return Result.ok(qIntervalConfigService.save(qIntervalConfig));
    }

    @Operation(summary = "修改间隔配置")
    @PreAuthorize("@ss.hasPermi('qb:qIntervalConfig:edit')")
    @Log(title = "间隔配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Boolean> edit(@Validated @RequestBody QIntervalConfig qIntervalConfig) {
        return Result.ok(qIntervalConfigService.update(qIntervalConfig));
    }

    @Operation(summary = "删除间隔配置")
    @PreAuthorize("@ss.hasPermi('qb:qIntervalConfig:remove')")
    @Log(title = "间隔配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result<Boolean> remove(@PathVariable Long[] ids) {
        return Result.ok(qIntervalConfigService.removeByIds(ids));
    }

    @Operation(summary = "导出间隔配置列表")
    @PreAuthorize("@ss.hasPermi('qb:qIntervalConfig:export')")
    @Log(title = "间隔配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @ParameterObject QIntervalConfig qIntervalConfig) {
        Wrapper<QIntervalConfig> wrapper = new QueryWrapper(qIntervalConfig);
        List<QIntervalConfig> list = qIntervalConfigService.list(wrapper);
        ExcelUtil<QIntervalConfig> util = new ExcelUtil<>(QIntervalConfig. class);
        util.exportExcel(response, list, "间隔配置数据");
    }

    @Operation(summary = "获取间隔配置详细信息")
    @PreAuthorize("@ss.hasPermi('qb:qIntervalConfig:query')")
    @GetMapping(value = "/{id}")
    public Result<QIntervalConfig> getInfo(@PathVariable("id") Long id) {
        return Result.ok(qIntervalConfigService.getById(id));
    }
}
